<?php

/**
 * Venta form.
 *
 * @package    administracion-ventas
 * @subpackage form
 * @author     Your name here
 * @version    SVN: $Id: sfPropelFormTemplate.php 10377 2008-07-21 07:10:32Z dwhittle $
 */
class VentaForm extends BaseVentaForm
{
    public function configure()
    {
        $form = new sfForm();
        $lineaVentaForm = new LineaVentaForm(null, array('url' => $this->getOption('url')));
        $removed_products = $this->getOption('removed_products', null);
        for ($i=0;$i<$this->getOption('nro', 1);$i++)
        {
            if ($removed_products)
                if (in_array((string)$i, $removed_products))
                    continue;
            $frm = clone $lineaVentaForm;
            $form->embedForm($i, $frm);
        }
        $this->embedForm('linea_venta', $form);
    }

    public function save($con = null)
    {
        $obj = parent::save($con);
        $ef = $this->getEmbeddedForms();
        $venta = $this->getObject();
        foreach ($ef as $f)
        {
            foreach ($f->getEmbeddedForms() as $f1)
            {
                $f1->getObject()->setVentaId($obj->getId());
                $f1->getObject()->save();
            }
        }

        return $obj;
    }
}
